const { signup, signin } = require('../model/user');
// const fs = require('fs');
// const path = require('path');

const userController = {
    signup: async({ username, password, res }) => {
        const flag = await signup({ username, password });
        let data = null;
        if (flag) {
            data = { rat: flag, msg: '注册成功' };
        } else {
            data = { rat: flag, msg: '注册失败' };
        }
        res.render('signup', {
            data: JSON.stringify(data)
        });
    },
    signin: async({ username, password, res }) => {
        const flag = await signin({ username, password });
        let data = null;
        if (flag) {
            data = { rat: flag, msg: '登录成功' };
        } else {
            data = { rat: flag, msg: '登录失败' };
        }
        res.render('signin', {
            data: JSON.stringify(data)
        });
    }
};

module.exports = userController;